package com.deng.codetemplate.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author 邓天天
 * @date 2021/4/26 21:22
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {
    public static final String SWAGGER2_SCAN_BASE_PACKAGE = "com.deng.codetemplate.controller";
    public static final String VERSION = "1.0.0";

    @Value("${swagger.enable}")
    private boolean enable;
    @Bean
    public Docket createResetApi(){

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(webApiInfo())
                .enable(enable)
                .select()
                .apis(RequestHandlerSelectors.basePackage(SWAGGER2_SCAN_BASE_PACKAGE))
                .paths(PathSelectors.any())
                .build();
    }


    private ApiInfo webApiInfo(){
        // 设置标题，文档描述,版本
        return new ApiInfoBuilder()
                .title("代码模版")
                .description("代码模版")
                .version(VERSION)
                .contact(new Contact("邓天天","www.baidu.com","wbdengtt@centaline.com.cn"))
                .build();
    }
}
